package UILayer;
import java.util.Scanner;
import CtrlLayer.*;
import ModelLayer.Employee;

public class EmployeeUI
{
	private PersonCtrl PC;
	private Employee myemployee;
	
    public EmployeeUI()
    {
    	PC = new PersonCtrl();
    }
    
    public void EmployeeMenu()
    {   
    	boolean exit = false;
        while (!exit) //! means while exit not is true (that is: false)
        {
        	int choise = writeEmployeeMenu();
        	switch(choise)
        	{
        		case 1: addEmployee(); break;
    			case 2: delEmployee(); break;
    			case 3: getEmployeeUI(); break;
    			case 4: listAllEmployee(); break;
        		case 99: exit = true; break;
        	}//end switch
        }//end while
    }
    
    private int writeEmployeeMenu()
    {
        //creates an object keyboard to read data from the keyboard
    	Scanner keyboard = new Scanner(System.in);
    	System.out.println(" *** Medarbejder Menu ***");
    	System.out.println(" (1) Opret Medarbejder");
    	System.out.println(" (2) Slet Medarbejder");
    	System.out.println(" (3) Find Medarbejder");
    	System.out.println(" (4) List alle Medarbejder");
    	System.out.println(" (99) Tilbage");
    	System.out.print("\n Make your choise: ");
    	int choise = keyboard.nextInt();
    	return choise;
    }
    
    public void addEmployee()
    {
    	String name = inputtext("Navn ");
    	String address = inputtext("Adresse ");
    	String postal = inputtext("Postnr ");
    	String city = inputtext("By ");
    	String phone = inputtext("Tlf ");
    	String email = inputtext("email ");
    	String username = inputtext("brugernavn ");
    	String password = inputtext("password ");
    	PC.createEmployee(name, address, postal, city, phone, email, username, password);
    }
    
    public void delEmployee()
    {
    	
    }
    
    public void getEmployeeUI()
    {
    	String phone = inputtext("Tlf ");
    	myemployee = getEmployee(phone);
    	System.out.println( myemployee.getName() );
    	System.out.println( myemployee.getAddress() );
    	System.out.println( myemployee.getPostal() + "  " + myemployee.getCity() );
    	System.out.println( "tlf: " + myemployee.getPhone() );
    	System.out.println( myemployee.getEmail() );
    	System.out.println( "bruger: " + myemployee.getUsername() );
    	System.out.println( "password: " + myemployee.getPassword() );
    }
    
    public Employee getEmployee(String phone)
    {
    	return PC.searchEmployee(phone);
    }
    
    public void listAllEmployee()
    {
    	
    }
    
    /**
     * Print a text and takes input from keyboard
     * @param text Print text
     * @return str Return the input from the keyboard 
     */
    private String inputtext(String text)
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.print(text + ": ");
        String str = keyboard.nextLine();
        return str;
    }
    
}